home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 November / Cd users extra 14.iso / prog / inst / inpoly / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-09-28  |  2.9 KB  |  103 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3195
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4680
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3195
  11.    ScaleWidth      =   4680
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.Label Label1 
  14.       Height          =   255
  15.       Left            =   120
  16.       TabIndex        =   0
  17.       Top             =   2880
  18.       Width           =   4455
  19.    End
  20. Attribute VB_Name = "Form1"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = False
  23. Attribute VB_PredeclaredId = True
  24. Attribute VB_Exposed = False
  25. Option Explicit
  26. Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
  27. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
  28. Private Type POINTAPI
  29.     X As Long
  30.     Y As Long
  31. End Type
  32. Private Const WINDING = 2
  33. Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal X As Long, ByVal Y As Long) As Long
  34. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  35. Private Points(1 To 25) As POINTAPI
  36. Private Sub Form_Load()
  37.     ScaleMode = vbPixels
  38.     ' Set some points.
  39.     Points(1).X = 75
  40.     Points(1).Y = 53
  41.     Points(2).X = 109
  42.     Points(2).Y = 72
  43.     Points(3).X = 138
  44.     Points(3).Y = 52
  45.     Points(4).X = 141
  46.     Points(4).Y = 79
  47.     Points(5).X = 213
  48.     Points(5).Y = 61
  49.     Points(6).X = 251
  50.     Points(6).Y = 100
  51.     Points(7).X = 199
  52.     Points(7).Y = 102
  53.     Points(8).X = 243
  54.     Points(8).Y = 127
  55.     Points(9).X = 224
  56.     Points(9).Y = 142
  57.     Points(10).X = 178
  58.     Points(10).Y = 131
  59.     Points(11).X = 178
  60.     Points(11).Y = 168
  61.     Points(12).X = 141
  62.     Points(12).Y = 168
  63.     Points(13).X = 147
  64.     Points(13).Y = 132
  65.     Points(14).X = 102
  66.     Points(14).Y = 138
  67.     Points(15).X = 104
  68.     Points(15).Y = 183
  69.     Points(16).X = 62
  70.     Points(16).Y = 173
  71.     Points(17).X = 73
  72.     Points(17).Y = 119
  73.     Points(18).X = 19
  74.     Points(18).Y = 113
  75.     Points(19).X = 32
  76.     Points(19).Y = 91
  77.     Points(20).X = 100
  78.     Points(20).Y = 98
  79.     Points(21).X = 100
  80.     Points(21).Y = 76
  81.     Points(22).X = 60
  82.     Points(22).Y = 71
  83.     Points(23).X = 18
  84.     Points(23).Y = 63
  85.     Points(24).X = 31
  86.     Points(24).Y = 38
  87.     Points(25).X = 39
  88.     Points(25).Y = 60
  89.     ' Draw the polygon.
  90.     Polygon hdc, Points(1), 25
  91. End Sub
  92. ' See if the point is inside the polygon.
  93. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  94. Dim rgn As Long
  95.     rgn = CreatePolygonRgn(Points(1), 25, WINDING)
  96.     If PtInRegion(rgn, X, Y) Then
  97.         Label1.Caption = "In the polygon"
  98.     Else
  99.         Label1.Caption = "Outside the polygon"
  100.     End If
  101.     DeleteObject rgn
  102. End Sub
  103.